using System.Windows.Forms;
using WindowsLive.Writer.Api;
using System.IO;

namespace Writerous
{
    [WriterPlugin("b1606dad-3f08-4757-a7a3-f151fa26ccba", "Writerous Files Plugin",
        PublisherUrl = "http://writerous.codeplex.com",
        Description = "A plugin to allow you to put files ready for Writerous to upload to Posterous",
        ImagePath = "writer.png",
        HasEditableOptions = false)]
    [InsertableContentSource("Writerous Files")]

    public class WriterousFilesPlugin : SmartContentSource
    {
        public override DialogResult CreateContent(IWin32Window dialogOwner, ISmartContent newContent)
        {
            using (frmInsertFiles form = new frmInsertFiles())
            {
                DialogResult result = form.ShowDialog();
                if (result == DialogResult.OK)
                {
                    foreach (var file in form.Files)
                    {
                        newContent.Files.Add(file.Name, file.FullName);
                    }
                    return DialogResult.OK;
                }
            }
            return DialogResult.Cancel;
        }
        public override SmartContentEditor CreateEditor(ISmartContentEditorSite editorSite)
        {
            return new ContentEditorForm();
        }

        public override string GeneratePublishHtml(ISmartContent content, IPublishingContext publishingContext)
        {
            return "";
        }

        public override string GenerateEditorHtml(ISmartContent content, IPublishingContext publishingContext)
        {
            string file = content.Files.Filenames.Length > 1 ? "files have" : "file has";
            return string.Format("Your {0} been inserted and will be uploaded when you publish.", file);
        }
    }
}
